import request from '@/utils/request.js'
import { getToken } from '@/utils/token.js'
let token = getToken()
import production from './image.js'

// 获取文章列表
export const reqArticleList = params => {
  return request({
    method: 'GET',
    headers: {
      Authorization: production.token
    },
    url: production.baseurl + 'mp/v1_0/articles',
    params
  })
}

// 获取文章频道
export const reqArticleChanle = () => {
  return request({
    headers: {
      Authorization: production.token
    },
    url: production.baseurl + 'mp/v1_0/channels'
  })
}

// 删除文章接口
export const reqDeleteArticle = articleId => {
  return request({
    headers: {
      Authorization: production.token
    },
    url: production.baseurl + `mp/v1_0/articles/${articleId}`
  })
}

// 新增文章接口
export const reqAddArticle = (data,draft = false) => {
  return request({
    method: 'POST',
    headers: {
      Authorization: production.token
    },
    url: production.baseurl + 'mp/v1_0/articles',
    params:{
      draft
    },
    data
  })
}

// 获取具体一篇文章详情
export const reqDetailArticle = articleId => {
  return request({
    method: 'GET',
    headers: {
      Authorization: production.token
    },
    url: production.baseurl + `mp/v1_0/articles/${articleId}`
  })
}

// 修改文章
export const reqUpdateArticle = (articleId,data,draft = false) => {
  console.log(draft)
  return request({
    method: 'PUT',
    headers: {
      Authorization: production.token
    },
    url: production.baseurl + `mp/v1_0/articles/${articleId}`,
    params: {
      draft
    },
    data
  })
}
